<template>
  <div>
    <!-- 搜索 -->
    <el-form :inline="true" :model="formSerach" class="demo-form-inline">
      <el-form-item label="姓名">
        <el-input v-model="formSerach.name" placeholder="姓名..."></el-input>
      </el-form-item>

      <el-form-item label="性别">
        <el-select v-model="formSerach.gender" placeholder="性别...">
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="2"></el-option>
        </el-select>
      </el-form-item>

      <!-- 日期区间 -->
      <el-form-item label="入职日期">
        <el-date-picker
          v-model="formSerach.entryDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table height="450px" stripe :data="tableData" style="width: 100%">
      <!-- 编号 -->
      <el-table-column align="center" prop="id" label="编号"> </el-table-column>
      <el-table-column align="center" prop="name" label="姓名"> </el-table-column>
      <el-table-column align="center" prop="image" label="头像" width="180">
        <template slot-scope="scope">
          <img :src="scope.row.image" width="90px" height="60px" />
        </template>
      </el-table-column>
      <el-table-column align="center" prop="gender" label="性别" width="140">
        <!-- slot-scope可以获取当前所在行中对象的所有属性 -->
        <template slot-scope="scope">
          {{ scope.row.gender == 1 ? "男" : "女" }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="job" label="岗位"> </el-table-column>
      <el-table-column align="center" prop="entrydate" label="入职日期"> </el-table-column>
      <el-table-column align="center" label="操作">
        <!-- 指定操作的项 -->
        <el-button size="mini" type="primary">编辑</el-button>
        <el-button size="mini" type="danger">删除</el-button>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
//使用axios
import axios from "axios";

export default {
  name: "EmpView",
  data() {
    return {
      //搜索表单数据
      formSerach: {
        name: "",
        gender: "",
        entryDate: [],
      },
      tableData: [], //表格的数据
      //分页相关数据
      currentPage: 1, //当前页
      total: 100, //总数据
      pageSize: 5, //每页显示条数
    };
  },
  methods: {
    //搜索按钮
    onSubmit() {
      console.log("点击搜索");
    },
    //显示条数发生改变
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    //当前页发生改变
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
  //页面挂载后加载数据
  mounted() {
    //使用axios发送ajax请求
    axios.get("http://localhost:10010/emp/list").then((resp) => {
      console.log(resp);
      this.tableData = resp.data.data;
    });
  },
};
</script>

<style>
</style>